//
//  BETitleHeaderReusableView.m
//  s.
//
//  Created by fanshijian on 2022/8/26.
//  Copyright © 2022 J. All rights reserved.
//

#import "BETitleHeaderReusableView.h"
#import "BETitleHeaderModel.h"

@interface BETitleHeaderReusableView ()

@property (weak, nonatomic) UILabel *titleLab;

@end

@implementation BETitleHeaderReusableView

- (UILabel *)titleLab {
    if (!_titleLab) {
        UILabel *obj = [UILabel new];
        [self addSubview:_titleLab = obj];
        [obj mas_makeConstraints:^(MASConstraintMaker *make) {
            kMakeLV(12);
            kMakeTV(24);
            kMakeRV(-12);
        }];
        obj.font = U_bfont(16);
        obj.textColor = KLColor(@"#000000");
    }
    return _titleLab;
}

- (void)setData:(BETitleHeaderModel *)data {
    if (self.data != data || data.modified) {
        [super setData:data];
        if (data.tf) self.titleLab.font = data.tf;
        if (data.title) {
            if ([data.title isKindOfClass:NSAttributedString.class]) {
                self.titleLab.attributedText = data.title;
            }else {
                self.titleLab.text = data.title;
            }
        }else {
            self.titleLab.text = @"";
        }
        self.titleLab.textAlignment = data.textAlignment;
        if (data.tColor) self.titleLab.textColor = KLColor(data.tColor);
        if (data.color) {
            self.backgroundColor = KLColor(data.color);
        }else {
            self.backgroundColor = [UIColor clearColor];
        }
        
        [self.titleLab mas_updateConstraints:^(MASConstraintMaker *make) {
            kMakeTV(data.topOffset);
            kMakeLV(data.leftOffset);
            if (data.titleH > 0) {
                kMakeHV(data.titleH);
            }
        }];
    }
}


@end
